package net.sureon.biz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CompanyConfigBO {
	private static Map<String, String> defaults = new HashMap<String, String>();
	public static final String MAP_KEY_ID = "ID";
	public static final String MAP_KEY_KEY = "CONFKEY";
	public static final String MAP_KEY_VALUE = "CONFVALUE";
	private Map<String, String> dbValues = new HashMap<String, String>();
	private static final String VISIBLE_DIRECT_GROUP_LEVEL = "visibleDirectGroupLevel";
	private static final String DAILY_TIMIG_REMIDER_DAY = "dailyTimingReminderInterval";

	// 主页logo
	public static final String INDEX_LOGO = "indexLogo";
	// 左上角图标
	private static final String LOGO_FOR_LEFTUP = "logoForLeftUp";
	// 左上角图标链接地址
	private static final String LINK_FOR_LEFTUP_LOGO = "linkForLeftUpLogo";
	// 网页右上角横幅广告
	private static final String ADVERTISING_FOR_RIGHTUP = "advertisingForRightUp";
	// 网页右上角横幅广告链接网址
	private static final String LINK_FOR_ADVERTISING_FOR_RIGHTUP = "linkForAdvertisingForRightUp";
	// 网页右下角管理员电子邮箱
	private static final String ADMIN_EMAIL = "adminEmail";
	// 网页右下角管理员电话号码
	private static final String ADMIN_TEL = "adminTel";
	// 用户N天没有对下属的考勤进行审核，发mail通知
	private static final String DAILYTIMING_REMINDER_APPROVE_INTERVAL = "dailyTimingReminderApproveInterval";
	// 直接上司在发mail后的n天还没有对用户进行审核,则系统自动审批
	private static final String AUTO_APPROVE_DAYS = "autoApproveDays";
	// 用户连续N天没有提交考勤记录，系统发mail通知
	// private static final String DAILYTIMING_REMINDER_INTERVAL =
	// "dailyTimingReminderInterval";
	// 公司的考勤周期是自然月吗？
	private static final String DAILYTIMING_IN_NATURAL_MONTH = "dailyTimingInNaturalMonth";
	// 公司的每月考勤起始日期
	private static final String DAILYTIMING_START_DATE_PER_MONTH = "dailyTimingStartDatePerMonth";
	// 每月的考勤统计表将发送到下面的电子邮件地址
	private static final String DAILYTIMING_STATISTICS_EMAIL_ADDRS = "dailyTimingStatisticsEmailAddrs";
	// 每月的消费记录对账单将发送到下面的电子邮件地址
	private static final String CONSUME_STATISTICS_EMAIL_ADDRS = "consumeStatisticsEmailAddrs";
	// 考勤记录需保存N 月
	private static final String DAILYTIMING_SAVED_MONTH = "dailyTimingSavedMonth";
	// 申请记录保存N月
	private static final String APPLICATION_SAVED_MONTH = "applicationSavedMonth";
	// 考勤统计需保存N月
	private static final String DAILYTIMING_STATISTICS_SAVED_MONTH = "dailyTimingStatisticsSavedMonth";
	// 消费记录需保存N月
	private static final String CONSUME_STATISTICS_SAVED_MONTH = "consumeStatisticsSavedMonth";

	static {
		defaults.put(VISIBLE_DIRECT_GROUP_LEVEL, "2");
		defaults.put(DAILYTIMING_REMINDER_APPROVE_INTERVAL, "5");
		defaults.put(AUTO_APPROVE_DAYS, "3");
		defaults.put(DAILY_TIMIG_REMIDER_DAY, "5");
		defaults.put(DAILYTIMING_START_DATE_PER_MONTH, "1");
		defaults.put(DAILYTIMING_SAVED_MONTH, "12");
		defaults.put(APPLICATION_SAVED_MONTH, "12");
		defaults.put(DAILYTIMING_STATISTICS_SAVED_MONTH, "12");
		defaults.put(CONSUME_STATISTICS_SAVED_MONTH, "12");
	}

	public CompanyConfigBO(List<Map> defList) {
		for (Map map : defList) {
			dbValues.put((String) map.get(MAP_KEY_KEY), (String) map
					.get(MAP_KEY_VALUE));
		}
	}

	public String getIndexLogo() {
		String str = getMergedVal(INDEX_LOGO);
		if(str != null) {
			return str;
		}
		return "";
	}
	
	public String getLogoForLeftUp() {
		String str = getMergedVal(LOGO_FOR_LEFTUP);
		if (str != null) {
			return str;
		}
		return "";
	}

	public String getLinkForLeftUpLogo() {
		String str = getMergedVal(LINK_FOR_LEFTUP_LOGO);
		if (str != null) {
			return str;
		}
		return "";
	}

	public String getAdvertisingForRightUp() {
		String str = getMergedVal(ADVERTISING_FOR_RIGHTUP);
		if (str != null) {
			return str;
		}
		return "";
	}

	public String getLinkForAdvertisingForRightUp() {
		String str = getMergedVal(LINK_FOR_ADVERTISING_FOR_RIGHTUP);
		if (str != null) {
			return str;
		}
		return "";
	}

	public String getAdminEmail() {
		String str = getMergedVal(ADMIN_EMAIL);
		if (str != null) {
			return str;
		}
		return "";
	}

	public String getAdminTel() {
		String str = getMergedVal(ADMIN_TEL);
		if (str != null) {
			return str;
		}
		return "";
	}

	// N天没有对用户进行审核，发mail通知
	public int getDailyTimingReminderApproveInterval() {
		String str = getMergedVal(DAILYTIMING_REMINDER_APPROVE_INTERVAL);
		if (str != null) {
			return Integer.parseInt(str);
		}
		return 0;
	}

	public int getAutoApproveDays() {
		String str = getMergedVal(AUTO_APPROVE_DAYS);
		if (str != null) {
			return Integer.parseInt(str);
		}
		return 0;
	}

	// public int getUserNotDailyTimingDays() {
	// String str = getMergedVal(DAILYTIMING_REMINDER_INTERVAL);
	// if(str != null) {
	// return Integer.parseInt(str);
	// }
	// return 0;
	// }
	// 默认为自然月
	public boolean getDailyTimingInNaturalMonth() {
		String str = getMergedVal(DAILYTIMING_IN_NATURAL_MONTH);
		if (str != null) {
			return Boolean.parseBoolean(str);
		}
		return true;
	}

	public int getDailyTimingStartDatePerMonth() {
		String str = getMergedVal(DAILYTIMING_START_DATE_PER_MONTH);
		if (str != null) {
			return Integer.parseInt(str);
		}
		return 0;
	}

	public String getDailyTimingStatisticsEmailAddrs() {
		String str = getMergedVal(DAILYTIMING_STATISTICS_EMAIL_ADDRS);
		if (str != null) {
			return str;
		}
		return "";
	}

	public String getConsumeStatisticsEmailAddrs() {
		String str = getMergedVal(CONSUME_STATISTICS_EMAIL_ADDRS);
		if (str != null) {
			return str;
		}
		return "";
	}

	public int getDailyTimingSavedMonth() {
		String str = getMergedVal(DAILYTIMING_SAVED_MONTH);
		if (str != null) {
			return Integer.parseInt(str);
		}
		return 0;
	}

	public int getApplicationSavedMonth() {
		String str = getMergedVal(APPLICATION_SAVED_MONTH);
		if (str != null) {
			return Integer.parseInt(str);
		}
		return 0;
	}

	public int getDailyTimingStatisticsSavedMonth() {
		String str = getMergedVal(DAILYTIMING_STATISTICS_SAVED_MONTH);
		if (str != null) {
			return Integer.parseInt(str);
		}
		return 0;
	}

	public int getConsumeStatisticsSavedMonth() {
		String str = getMergedVal(CONSUME_STATISTICS_SAVED_MONTH);
		if (str != null) {
			return Integer.parseInt(str);
		}
		return 0;
	}

	public int getVisibleDirectGroupLevel() {
		String o = getMergedVal(VISIBLE_DIRECT_GROUP_LEVEL);
		if (o != null) {
			return Integer.parseInt(o);
		}
		return 0;
	}

	public int getDailyTimingReminderInterval() {
		String o = getMergedVal(DAILY_TIMIG_REMIDER_DAY);
		if (o != null) {
			return Integer.parseInt(o);
		}
		return 0;
	}

	// public String getLogoForLeftUp() {
	// String o = getMergedVal(LOGO_FOR_LEFTUP);
	// if(o != null) {
	// return o;
	// }
	// return "";
	// }

	private String getMergedVal(String key) {
		if (isItemDefined(key)) {
			String str = dbValues.get(key);
			if(str != null){
				str = str.trim();
			}
			return str;
		}
		return defaults.get(key);
	}

	public boolean isItemDefined(String key) {
		return dbValues.containsKey(key);
	}
}
